/**********************************************************************************************
Do-file:		Misreporting upper bound.do
Date:			8th February 2021
Author:			Jennifer Mayo
Description:	Table and Figure for rated vs unrated
***********************************************************************************************/


clear
set more off

global name "jmp4k"
global home "/Users/$name/Library/CloudStorage/OneDrive-UniversityofMissouri/Projects/Navigating the notches"
global data "$home/Replication"
global output "$home/CN Output"

use "$data/RatedvsUnrated.dta", clear
set scheme s1mono


************************************************************************

sort ein modate, stable

// Which charities have rev > $1 million
gen rev_over_1m = 1 if totalrevcurrent>1000000
by ein: gen temp = rev_over_1m - rev_over_1m[_n-1]   // temp = 0 if over $1m for 2 consecutive years
gen consecutive_rev = 1 if rev_over_1m==1 & temp==0
drop temp

// At least $500,000 of public support AND public support is >40% of total rev for at least 2 years
gen support_rev = totalcontributions/totalrevcurrent
gen support_40 = 1 if support_rev>0.4
by ein: gen temp = support_40 - support_40[_n-1]   // temp = 0 if over >40% for 2 consecutive years
gen consecutive_40 = 1 if support_40==1 & temp==0 
drop temp

// >1% of expenses are fundraising for at least 3 years  
destring totfundexp, replace
gen fund_exp = totfundexp/totalexpcurrent
gen fund_1 = 1 if fund_exp>0.01
by ein: gen temp = fund_1 - fund_1[_n-1]   // temp = 0 if over >1% for 2 consecutive years
by ein: gen temp2 = temp - temp[_n-1]   // temp2 = 0 if over >1% for 3 consecutive years
gen consecutive_1fund = 1 if fund_1==1 & temp==0 & temp2==0
drop temp*

duplicates drop

** pe_te and we_te
replace totalprogservexp=. if totalprogservexp==0
gen prog_totalexp = totalprogservexp/totalexpcurrent
replace prog_totalexp=. if prog_totalexp<0
replace prog_totalexp=. if prog_totalexp>1

gen wage_totalexp = salariescurrent/totalexpcurrent
gen wage_progexp = salariescurrent/totalprogservexp

replace wage_totalexp=. if wage_totalexp==0
replace wage_totalexp=. if wage_totalexp>1
replace wage_progexp=. if wage_progexp==0

*** Rated vs unrated
gen unrated = 1 if consecutive_rev==1 & consecutive_40==1 & consecutive_1fund==1 & score==.  
label var unrated "Charity meets criteria this year but is unrated"
by ein: egen temp1=max(score)
by ein: egen temp2=max(unrated)
gen neverrated=1 if temp1==. & temp2!=. // charity meets rating criteria at some point but never rated
replace neverrated=0 if neverrated==.
label var neverrated "Charity meets rating criteria at some point but never rated"
gen ratedinthefuture = 1 if temp1!=. & temp2!=. & score==. 
label var ratedinthefuture "Charity is rated in the future but not this year (may or may not meet the criteria this year)"
// if temp1!=. & temp2!=. then charity is rated at some point i.e. not never rated
gen everrated = 1 if temp1!=.
label var everrated "Charity rated at some point"
gen firsttimerated = 1 if score!=. & temp1!=. & score[_n-1]==. & temp1[_n-1]!=.
label var firsttimerated "Dummy var indicating this is the year that charity is rated for the first time"
gen rated = 1 if score!=.
replace rated = 0 if score==.
label var rated "Charity rated this year"


****************************
**** APPENDIX FIGURE D7 ****
****************************

label var prog_totalexp "pe_te"

kdensity prog_totalexp if score!=. & wage_progexp<1.127709, addplot(kdensity prog_totalexp if unrated==1 & wage_progexp<1.127709, lpattern(dash)) graphregion(color(white)) legend(order(1 "Rated" 2 "Unrated") title("") ring(0) pos(9) cols(1) size(*0.6) rowgap(*0.1) symxsize(*0.6) region(style(none)))

graph export "$output/FigureD7.eps", replace


***************************
**** APPENDIX TABLE C7 ****
***************************

// rated == 1 means rated in that given year
// unrated == 1 means unrated in that given year (and meet the criteria)

** Are charities really rated randomly at the margin?
gen ratedvsnever = 1 if ratedinthefuture==1 
replace ratedvsnever = 0 if neverrated==1
label var ratedvsnever "Dummy=1 if ratedinthefuture==1 and 0 if neverrated==1"

destring totemployee, replace 
replace totvolunteers="" if totvolunteers=="NA"
destring totvolunteers, replace
destring fndeventsexp, replace

xtset ein fisyr 

gen ln_totemployee = log(totemployee)
gen ln_totvolunteers = log(totvolunteers)
gen ln_totalcontributions = log(totalcontributions)
gen ln_fndeventsexp = log(fndeventsexp)
gen ln_salariescurrent = log(salariescurrent)

eststo prob_rated: logit ratedvsnever ln_totemployee ln_totvolunteers ln_totalcontributions ln_fndeventsexp ln_salariescurrent if score==., vce(cluster ein) 


esttab prob_rated ///
  using "$output/prob_rated.tex", ///
  replace label nogap nonote ///
  se ///
  mlabels("\shortstack{Probability of being rated (Logit Model) - 2002-19}") ///
  keep(ln_totemployee ln_totvolunteers ln_totalcontributions ln_fndeventsexp ln_salariescurrent) ///
  order(ln_totemployee ln_totvolunteers ln_totalcontributions ln_fndeventsexp ln_salariescurrent) ///
  varlabels( ///
            ln_totemployee "Number of paid employees" ///
			ln_totvolunteers "Number of volunteers" ///
            ln_totalcontributions "Total contributions" ///
            ln_fndeventsexp "Fundraising expenses" ///
			ln_salariescurrent "Total wage bill" ///
            ) ///
  nonumbers ///
  eqlabels(none) ///
  collabels(none) ///
  star(* 0.1 ** 0.05 *** 0.01) ///
  legend ///
  addnotes("Notes: The dependent variable equals 1 if a charity is rated at some point in the sample period, and 0 if they remain unrated" "All explanatory variables are in logs" "Standard errors (in parentheses) clustered at the charity level") ///
  stats( N r2_p, fmt(%9.0g) ///
        labels("Observations" ///
               "R-Squared" ///
               ) ///
       ) ///
  title("Probability of Being Rated")
